<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.hz.util.ParamUtil"%>
<%@page import="com.hz.control.UserControl"%>
<%@page import="com.hz.model.User"  %>
<%@page import="java.util.*"%>
<%@page import="com.hz.util.GradeList"%>
<%@page import="com.hz.control.ParamDepartmentManager"%>
<%@page import="java.util.ArrayList"%>
<%@page import="com.hz.model.ParamDepartment"%>
<%@page import="com.hz.control.ParamSpecialManage"%>
<%@page import="com.hz.control.ActivityControl"%>
<%@page import="com.hz.model.Activity"%>
<%@page import="com.hz.control.HobbyControl"%>
<%@page import="com.hz.model.Hobby"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="../common/js/jquery.js"></script>
<script type="text/javascript" src="../common/js/getMajors.js"></script>
<script type="text/javascript">
	$(function(){
		$(".odd tbody tr:odd").css('background','#eee');
	});
</script>
<link rel="stylesheet" type="text/css" href="../../css/active.css"/>

</head>
<body>
 <h1 class='title'>用户信息</h1>
<%
           request.setCharacterEncoding("utf-8");
           //System.out.println(currenttime);
           //System.out.print(user.getId());
           //可供查询的字段
           String departmentId = "";
           String specialId="";
           String role = "";
           String grade="";
           String stuLev="";
           String volLev="";
           String volNo="";
           String stuNum="";
           String name="";
           String actId="";
           String hobby="";
           
           
           
           
           
           int type=ParamUtil.getInt(request,"type",0);
           //System.out.print(type);
           if(type==1){
                name = ParamUtil.getString(request,"name",null);
                stuNum = ParamUtil.getString(request,"stuNum",null);
                volNo = ParamUtil.getString(request,"volNo",null);
               
                stuLev = ParamUtil.getString(request,"stuLev",null);
                hobby = ParamUtil.getString(request,"hobby",null);
                volLev=ParamUtil.getString(request,"volLev",null);
                actId=ParamUtil.getString(request,"actId",null);
                role=ParamUtil.getString(request,"role",null);
                grade=ParamUtil.getString(request,"grade",null);
                departmentId=ParamUtil.getString(request,"departmentId",null);
                specialId=ParamUtil.getString(request,"specialId",null);
                
                session.setAttribute("serachdid",specialId);//与获取专业中session保持一致
                session.setAttribute("grade",grade);
                session.setAttribute("departmentId",departmentId);
                session.setAttribute("stuLev",stuLev);
                session.setAttribute("actId",actId);
                session.setAttribute("role",role);
                session.setAttribute("volLev",volLev);
                session.setAttribute("hobby",hobby);
                System.out.print(session.getAttribute("volLev"));
            
           
            }
            else{
               grade = (String)session.getAttribute("grade");
               departmentId = (String)session.getAttribute("departmentId");
               stuLev = (String) session.getAttribute("stuLev");
               actId = (String)session.getAttribute("actId");
               volLev = (String)session.getAttribute("volLev");
               role = (String)session.getAttribute("role");
               specialId = (String)session.getAttribute("serachdid");
               hobby = (String)session.getAttribute("hobby");
              // System.out.print(syid);
              System.out.print(volLev);
                
            }
           
           //session.setAttribute("name",name);
           //session.setAttribute("stunum",stunum);
           

 %>
<form name="form1" action="userslist.jsp?type=1" method="post">
<table class='add'><tr>
<td>姓名<input class='w175' type="text" name="name" /></td>
<td>学号<input class='w175' type="text" name="stuNum" /></td>
</tr>
<tr>
<td><select style='width:216px;' name="departmentId" id="departmentId">
<option value="">-选择学院和专业-</option>
<% 
    ArrayList<ParamDepartment> pd = ParamDepartmentManager.getAllDepartment(0);
    for(int i=0;i<pd.size();i++){
        ParamDepartment p = pd.get(i);  
 %>
<option value="<%=p.getId() %>"<%if(session.getAttribute("departmentId")!=null&&session.getAttribute("departmentId").equals(p.getId()+""))out.print("selected='selected'"); %>><%=p.getDepartmentName() %></option>
<%} %>
</select></td>
<td><select style='width:216px;' name="majorId" id="majorId">
</select></td>
</tr>
<tr>
<td>年级<select style='width:190px;' name="grade">
<option value="">-请选择-</option>
<%
       int gradelist[] = GradeList.getGradeList();
       for(int i=0;i<gradelist.length;i++){
 %>
<option value="<%=gradelist[i] %>" <%if(session.getAttribute("grade")!=null&&session.getAttribute("grade").equals(gradelist[i]+""))out.print("selected='selected'"); %> ><%=gradelist[i] %></option>
<%} %>
</select></td>
<td>服务类型<select style='width:190px;' name="hobby">
<option value="">-选择类型-</option>
<%
     Collection<Hobby> hc = HobbyControl.getAllHobbies();
     Iterator<Hobby> ith = hc.iterator();
     while(ith.hasNext()){
         Hobby h = ith.next();
 %>
 <option value="<%=h.getId() %>"<%if(session.getAttribute("hobby")!=null&&session.getAttribute("hobby").equals(h.getId()+""))out.print("selected='selected'"); %>><%=h.getHobbyName() %></option>
 <%} %>
</select></td>
</tr><tr>
<td>编号<input type="text" style='width:180px;' name="volNo"></td>
<td>角色<select style='width:190px;' name="role">
<option value="">-请选择-</option>
<option value="0"<%if(session.getAttribute("role")!=null&&session.getAttribute("role").equals("0"))out.print("selected='selected'"); %>>普通用户</option>
<option value="1"<%if(session.getAttribute("role")!=null&&session.getAttribute("role").equals("1"))out.print("selected='selected'"); %>>管理员</option>
</select></td>
</tr>
<tr>
<td>星级<select style='width:190px;' name="volLev">
<option value="" <%if(session.getAttribute("volLev")==null||session.getAttribute("volLev").equals(""))out.print("selected='selected'"); %>>-选择星级-</option>
<option value="0"<%if(session.getAttribute("volLev")!=null&&session.getAttribute("volLev").equals("0"))out.print("selected='selected'"); %>>0</option>
<option value="1"<%if(session.getAttribute("volLev")!=null&&session.getAttribute("volLev").equals("1"))out.print("selected='selected'"); %>>一星</option>
<option value="2"<%if(session.getAttribute("volLev")!=null&&session.getAttribute("volLev").equals("2"))out.print("selected='selected'"); %>>二星</option>
<option value="3"<%if(session.getAttribute("volLev")!=null&&session.getAttribute("volLev").equals("3"))out.print("selected='selected'"); %>>三星</option>
<option value="4"<%if(session.getAttribute("volLev")!=null&&session.getAttribute("volLev").equals("4"))out.print("selected='selected'"); %>>四星</option>
<option value="5"<%if(session.getAttribute("volLev")!=null&&session.getAttribute("volLev").equals("5"))out.print("selected='selected'"); %>>五星</option>
</select></td>
<td>参与活动<select style='width:160px;' name="actId">
<option value="">-选择活动-</option>
<%
    Collection<Activity> acs = ActivityControl.getActivities();
    Iterator<Activity>  itacs = acs.iterator();
    while(itacs.hasNext()){
       Activity a = itacs.next();
 %>
<option value="<%=a.getId()%>"><%=a.getActName() %></option>
<%} %>
</select></td>
</tr>
<tr>
<td COLSPAN='2'>
<input type="submit" name="submit"value="显示" />&nbsp;&nbsp;&nbsp;
<input type="button" onclick="window.location.href='ExportUsers.jsp'" value="导出显示部分" />
</td></tr>
</table>
</form>
<form action="userslist.jsp" method="post">
<fieldset>
<table class='add odd'>
<thead>
					<tr>
						<td>学号 </td>
			            <td>姓名</td>
						<td>年级</td>
						<td>学院</td>
						<td>专业</td>
						<td>星级</td>
						<td>操作</td>
					</tr>
				</thead>
				<tbody>
<%
          
           
           int pages = ParamUtil.getInt(request, "pages", 1);
		   int rowsPerPage = ParamUtil.getInt(request, "pageSize", 10);
		  
		   UserControl sc = new UserControl();
		   User member = new User();
		   List<User> list = new ArrayList<User>();
		   Collection<User> list2 = new ArrayList<User>();
		   list = (List) sc.getUsersByMulti(name,stuNum,departmentId,specialId,grade,stuLev,role,volNo,volLev,actId,hobby,pages,rowsPerPage);
		   list2 = sc.getAllUsersByMulti(name,stuNum,departmentId,specialId,grade,stuLev,role,volNo,volLev,actId,hobby);
						session.setAttribute("ulist",list2);
						for (int i = 0; i < list.size(); i++) {
							member = list.get(i);
					%>
					<tr>
						<td><%=member.getStuNum()%></td>
						<td><a href="../user/userinfo.jsp?userid=<%=member.getId()%>"><%=member.getRealname()%></a></td>
						<td><%=member.getGrade()%></td>
						<td><%=ParamDepartmentManager.findDepartment(member.getDepartmentId()).getDepartmentSmallName()%></td>
						<td><%=ParamSpecialManage.getSpecialById(member.getMajorId()).getSpecialName() %></td>
						<td><%=member.getVolunteerLev() %></td>
						<td><a href="delete_user.jsp?userid=<%=member.getId()%>" onclick="return confirm('确认删除？')">删除</a></td>
					</tr>
					<%
						}
					%>
			</table>
			</fieldset>
			<center><%
			out.println(UserControl.pageInstance.getToolsMenu(pages));
			%></center>
			</form>
         

</html>